﻿/*
Copyright © 2010 François Karman

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

See <license.txt> for the complete license of the software.
*/

using System.Windows;

namespace Faz.Dependencies.Controls
{
    /// <summary>
    /// Represents a rectangle where the position is based on its center, not its top-left corner.
    /// </summary>
    public struct LinkViewRect
    {
        /// <summary>
        /// The center of the rectangle.
        /// </summary>
        private Point center;

        /// <summary>
        /// The size of the rectangle.
        /// </summary>
        private Size size;

        /// <summary>
        /// Initializes a new instance of the LinkViewRect structure based on a specific center and size.
        /// </summary>
        /// <param name="center">The center of the rectangle.</param>
        /// <param name="size">The size of the rectangle.</param>
        public LinkViewRect(Point center, Size size)
        {
            this.center = center;
            this.size = size;
        }

        /// <summary>
        /// Gets the center of the rectangle.
        /// </summary>
        public Point Center
        {
            get { return this.center; }
        }

        /// <summary>
        /// Gets the size of the rectangle.
        /// </summary>
        public Size Size
        {
            get { return this.size; }
        }

        /// <summary>
        /// Compares two instances of the <see cref="LinkViewRect"/> structure.
        /// </summary>
        /// <param name="first">The first instance.</param>
        /// <param name="second">The second instance.</param>
        /// <returns>
        /// <c>true</c> if and only if both instances have the same center and size;
        /// <c>false</c> otherwise.
        /// </returns>
        public static bool operator ==(LinkViewRect first, LinkViewRect second)
        {
            return object.Equals(first, second);
        }

        /// <summary>
        /// Compares two instances of the <see cref="LinkViewRect"/> structure.
        /// </summary>
        /// <param name="first">The first instance.</param>
        /// <param name="second">The second instance.</param>
        /// <returns>
        /// <c>true</c> if the instances don't have the same center or size;
        /// <c>false</c> otherwise.
        /// </returns>
        public static bool operator !=(LinkViewRect first, LinkViewRect second)
        {
            return !object.Equals(first, second);
        }

        /// <summary>
        /// Compares the current instance with an other object.
        /// </summary>
        /// <param name="obj">The second object.</param>
        /// <returns>
        /// <c>true</c> if <paramref name="obj"/> is a <see cref="LinkViewRect"/> instance and has
        /// the same center and size; <c>false</c> otherwise.
        /// </returns>
        public override bool Equals(object obj)
        {
            if (!(obj is LinkViewRect))
            {
                return false;
            }

            LinkViewRect other = (LinkViewRect)obj;
            return object.Equals(this.Center, other.Center)
                && object.Equals(this.Size, other.Size);
        }

        /// <summary>
        /// Computes the hash code based on the current center and size.
        /// </summary>
        /// <returns>
        /// The hash code associated to the internal state of the object.
        /// </returns>
        public override int GetHashCode()
        {
            return (this.Center.GetHashCode() << 8) + this.Size.GetHashCode();
        }
    }
}
